
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class HoutaiSetUI : MonoBehaviour
{

    [SerializeField] private Button[] buttonList;
    [SerializeField] private GameObject buttonListParent;
    [SerializeField] private SetSelect setSelect;

    [SerializeField] private TextMeshProUGUI title;
    [SerializeField] private TextMeshProUGUI jichuSet;
    [SerializeField] private TextMeshProUGUI zhangmuSet;
    [SerializeField] private TextMeshProUGUI yingjianSet;
    [SerializeField] private TextMeshProUGUI languageSet;
    [SerializeField] private TextMeshProUGUI esc;

    private int index = 0;
    void Start()
    {
        buttonList = buttonListParent.GetComponentsInChildren<Button>();
        buttonList[index].Select();
    }

    void Update()
    {
        HoutaiSelect();

        if (Input.GetKeyDown(KeyCode.J) || ComTrans.Instance.GetsecSerial() || ComTrans.Instance.GetsetSerial())
        {
            buttonList[index].onClick.Invoke();
        }
        SetText();
    }
    // 选择
    private void HoutaiSelect()
    {
        if (Input.GetKeyDown(KeyCode.Q) || ComTrans.Instance.GetHorizontalL() == -1)
        {
            if (--index < 0) index = buttonList.Length - 1;
        }
        if (Input.GetKeyDown(KeyCode.E) || ComTrans.Instance.GetHorizontalR() == 1)
        {
            if (++index >= buttonList.Length) index = 0;
        }
        buttonList[index].Select();
    }
    // 设置文本
    private void SetText()
    {
        if (setSelect.language == 0)
        {
            title.text = "后台设置";
            jichuSet.text = "基础设置";
            zhangmuSet.text = "账目查询";
            yingjianSet.text = "硬件测试";
            languageSet.text = "语言设置";
            esc.text = "退出设置";
        }
        else if (setSelect.language == 1)
        {
            title.text = "Backend settings";
            jichuSet.text = "Basic Settings";
            zhangmuSet.text = "Account inquiry";
            yingjianSet.text = "Hardware Testing";
            languageSet.text = "Language settings";
            esc.text = "Exit Setup";
        }

    }

}
